﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using TR0217.ControlEx;
using System.Runtime.InteropServices;

namespace WindowsApplication1
{
    public partial class Form1 : CustomBorderForm
    {
        public Form1()
        {
            InitializeComponent();
        }

        [DllImport("user32.dll")]
        public static extern bool ReleaseCapture();

        [DllImport("user32.dll")]
        public static extern int SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);

        private void navigateBar1_MouseDown(object sender, MouseEventArgs e)
        {
            if (this.WindowState != FormWindowState.Maximized
                && e.Button == MouseButtons.Left
                && navigateBar1.ImageBounds.Contains(e.Location))
            {
                ReleaseCapture();
                SendMessage(this.Handle, 0xA1, 0x02, 0);
                SendMessage(navigateBar1.Handle, 0x202, 0, 0);
            }
        }
        private void label1_PartClick(object sender, PartClickEventArgs e)
        {
            if (e.Index == 1)
            {
                Application.Exit();
            }
        }

        private void label2_PartClick(object sender, PartClickEventArgs e)
        {
            switch (e.Index)
            {
                case 0:
                    this.WindowState = FormWindowState.Maximized;
                    break;
                case 1:
                    this.WindowState = FormWindowState.Minimized;
                    break;
                case 2:
                    this.WindowState = FormWindowState.Normal;
                    this.Refresh();
                    break;
                default: break;
            }
        }

        private void navigateBar1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            //if (navigateBar1.ImageBounds.Contains(e.Location))
            {
                WindowState = WindowState == FormWindowState.Normal ? FormWindowState.Maximized : FormWindowState.Normal;
            }
        }

        protected override void OnResizeEnd(EventArgs e)
        {
            base.OnResizeEnd(e);
            if (this.Width <= 500)
                this.Width = 500;
            if (this.Height < 103)
                this.Height = 103;
        }
    }
}